﻿@using LanDBom.Models
@using LanDBom.Resources
@{
    ViewBag.Title = "BomsView";
    Layout = "~/Views/Shared/_Genertals.cshtml";
}
@section styles{
    <style>
        .tab-shi tr td{
            width:50%;
        }
    </style>
    }
<from>
    <fieldset class="boun">
        <legend></legend>
        <div class="row bian">
            <label class="col-sm-3 breadcrumb-item">步骤八：审批流表</label>
            <ul id="lisul" class="row col-sm-5">
                <li class="lisu"></li>&rArr;
                <li class="lisu"></li>&rArr;
                <li class="lisu"></li>&rArr;
                <li class="lisu"></li>&rArr;
                <li class="lisu"></li>&rArr;
                <li class="lisu"></li>&rArr;
                <li class="lisu"></li>&rArr;
                <li class="lisu">8</li>
            </ul>
        </div>
    </fieldset>
</from>
<div>
    <div class="Zhuyags">
        <div class="col-2 nav-item" id="divjibeng">基本信息</div>
        <div class="col-2 nav-item" id="divbeizhu">项目备注</div>
        <div class="col-2 nav-item" id="divtuzhi">图纸沟通</div>
        <div class="col-2 nav-item" id="divweituo" style="display:none">设计委托</div>
    </div>
    <div>
        <div id="div1" style="display:block">
            <form action="/" method="post" class="boun">
                <fieldset class="boun">
                    <legend class="len1 ">@Resource.String428</legend>
                    <table class="table" style="width:80%" align="left">
                        @foreach (var item in ViewBag.ListAPP as List<Applications>)
                        {
                            <tr>
                                <td style="width:50%;">
                                    @Html.Label(Resource.String429): @item.App_Kehu
                                </td>
                                <td style="width:50%;">
                                    @Html.Label(Resource.String430):<label id="hunf">@item.AP_bian </label>
                                </td>
                            </tr>
                            <tr>
                                <td>@Html.Label(Resource.String431): @item.App_qishi</td>
                                <td>@Html.Label(Resource.String432):@item.App_JTime</td>
                            </tr>
                            <tr>
                                <td>@Html.Label(Resource.String433): @item.APP_name</td>
                                <td>@Html.Label(Resource.String434): @item.App_lei</td>
                            </tr>
                            <tr>
                                <td>@Html.Label(Resource.String435): @item.APP_Zhong</td>
                                <td style="width:50%;">@Html.Label(Resource.String436): <lable id="leb"></lable></td>
                            </tr>
                            <tr>
                                <td>@Html.Label(Resource.String437):@item.App_dizhi</td>
                                <td>@Html.Label(Resource.String438): @item.App_sho</td>
                            </tr>
                        }
                    </table>
                </fieldset>
            </form>
        </div>
        @*项目备注*@
        <div id="div2" style="display:none">
            <div class="">
                <fieldset class="boun">
                    <legend class="len">项目备注</legend>
                    <div id="div2_div">

                    </div>
                    <textarea rows="4" class="col-11" id="RZ_xznr"></textarea><br />
                    <input type="button" name="name" value="提交" id="RZ_tjrz" />
                </fieldset>
            </div>
        </div>
        @*图纸备注*@
        <div id="div3" style="display:none">
            <div class="">
                <fieldset class="boun">
                    <legend class="len">图纸沟通</legend>
                    <table class="table tab">
                        <thead style="text-align:center;">
                            <tr style="background-color: #6e95bc">
                                <td>序号</td>
                                <td>文件名</td>
                                <td>上传时间</td>
                                <td>上传人</td>
                                <td>下载</td>
                            </tr>
                        </thead>
                        <tbody id="div3__tb">
                        </tbody>
                    </table>
                </fieldset>
            </div>
        </div>
    </div>
   
    <div title="工艺详细" id="BJ_GYXX" style="display:none;position:fixed;" class="CenterDiv1">
        <div>
            <table class="table table-sm gun" style="background-color:darkgray;">
                <thead class="thead-light">
                    <tr>
                        <th scope="col">序号</th>
                        <th scope="col">印刷</th>
                        <th scope="col">印色</th>
                        <th scope="col">模切</th>
                        <th scope="col">木箱包角</th>
                        <th scope="col">表面处理</th>
                        <th scope="col">模具</th>
                        <th scope="col">提供模具</th>
                        <th scope="col">物理要求</th>
                        <th scope="col">加工费</th>
                    </tr>
                </thead>
                <tbody data-spy="scroll" style="background-color:darkgray;" id="BJ_oper_tbody">
                </tbody>
            </table>
            <div id="BJ_GYFH">
                返回
            </div>
        </div>
    </div>
    <div title="Bom详情">
        <div>
            <table class="table table-sm gun">
                <thead class="thead-light">
                    <tr>
                        <th scope="col">序号</th>
                        <th scope="col">层次</th>
                        <th scope="col">物料信息</th>
                        <th scope="col">料号</th>
                        <th scope="col">单位</th>
                        <th scope="col">客户料号</th>
                        <th scope="col">年用量</th>
                        <th scope="col">Bom用量</th>
                        <th scope="col">供应商</th>
                        <th scope="col">阶梯</th>
                        <th scope="col">价格(添加利润前)</th>
                        <th scope="col">利润</th>
                        <th scope="col">价格(添加利润后)</th>
                    </tr>
                </thead>
                <tbody data-spy="scroll" id="BJ_BOM_tbody">
                </tbody>
            </table>
        </div>
    </div>
    <button class="btn" id="btnsd">生成报价单</button>
    @section scripts{
        <script src="~/Scripts/jquery-3.4.1.min.js"></script>
        <script>
            $(function () {
                var names = $("#hunf").text();
                $.ajax({
                    url: "/Detailed/BomsView",
                    type: "POST",
                    data: { "names": names, "state": 1 },
                    success: function (date) {
                        createTR(date)
                    },
                    error: function () {
                        alert("Error")

                    }
                })
                $("#btnsd").click(function () {
                    if (confirm("是否上传至ERP销售报价单！")) {
                        var shen = $("#hunf").text();
                        $.ajax({
                            url: "/Detailed/BomsView",
                            type: "POST",
                            data: { "names": shen, "state": 4 },
                            success: function (date) {
                                console.log(date)
                                let shu = /提交成功/
                                let hund = date.match(shu)
                                console.log(hund);
                                if (hund != null) {
                                    alert("已提交至ERP销售报价单" + date)
                                    window.location.href = "/Home/Shenqingdan"
                                } else {
                                    alert(date)
                                }
                            },
                            error: function () {
                                alert("Error")
                            }
                        })
                    }
                })
            })

            function createTR(date) {
                $('#BJ_BOM_tbody tr').remove();
                $.each(date, function (i, item) {
                    var hun = item.BOM2_mioa;
                    if (item.BOM2_chen != "Leve0") {
                        hun = "";
                    }
                    var $tr = $(`
                                    <tr>
                                        <td></td>
                                        <td style="display:none;">${item.BOM2_id}</td>
                                        <td>${item.BOM2_chen}</td>
                                        <td>${item.BOM2_wuLiu}</td>
                                        <td>${item.BOM2_liao}</td>
                                        <td>${item.BOM2_fenzi}</td>
                                        <td>${item.BOM2_duan}</td>
                                        <td>${item.BOM2_Nian}</td>
                                        <td>${item.BOM2_Yong}</td>
                                        <td>${item.Nd_Gong}</td>
                                        <td>${item.BOM2_sd}</td>
                                        <td >${item.Nd_jiage}</td>
                                        <td>${item.BOM2_Jin}%</td>
                                        <td style="display:none">${item.BOM2_Gong}</td>
                                        <td style="font-size:20px;">${hun}</td>
                                    </tr>
                                `);
                    $('#BJ_BOM_tbody').append($tr);
                })
                var len = $('#BJ_BOM_tbody tr').length;
                for (var i = 0; i < len; i++) {
                    $('#BJ_BOM_tbody tr:eq(' + i + ') td:first').text(i + 1);
                }

            }
            $(document).on("click", "#BJ_CKGY", function (e) {
                $("#BJ_GYXX").css({ "display": "block" })
                var BOM_Gong = $(e.target).prev().text()
                $.ajax({
                    url: "/Detailed/BomsView",
                    type: "POST",
                    data: { "BOM_Gong": BOM_Gong, "state": 2 },
                    success: function (data) {
                        createTR(data)
                    },
                    error: function () {
                        alert("Error")

                    }
                })
                function createTR(data) {
                    $('#BJ_oper_tbody tr').remove();
                    $.each(data, function (i, item) {
                        var $tr = $(`
                                                <tr>
                                                    <td>${item.OP_ID}</td>
                                                    <td>${item.OP_Yin}</td>
                                                    <td>${item.OP_YinSe}</td>
                                                    <td>${item.OP_Muqie}</td>
                                                    <td>${item.OP_Muxinag}</td>
                                                    <td>${item.OP_biao}</td>
                                                    <td>${item.OP_Mujiu}</td>
                                                    <td>${item.OP_Tigong}</td>
                                                    <td>${item.OP_Wuli}</td>
                                                    <td>${item.OP_price}</td>
                                                </tr>
                                            `);
                        $('#BJ_oper_tbody').append($tr);
                    })
                }
            })
            $(document).on("click", "#BJ_GYFH", function () {
                $("#BJ_GYXX").css({ "display": "none" })
            })
            //实现页面显示BOM
            $(function () {
                gettuz()//搜索图纸信息
                gettbz()//搜索备注信息
                $('select[name="selop"]').change(function () {
                    var shun = $('select[name="selop"] option:selected').val();
                    var ghjd = $("#shenDan").text();
                    $.ajax({
                        url: "/Detailed/Boms",
                        type: "POST",
                        data: { "binaed": shun, "hudnf": ghjd, "state": 3 },
                        success: function (sdf) {
                            creaBOM(sdf);
                        },
                        error: function () {
                            alert("erroer");
                        },
                    })
                })
                $("#addwl").click(function () {
                    $("#JINDN").toggle()
                    $("#Yin").hide()
                })
                $("#addw3").click(function () {
                    $("#JINDN").hide()
                    $("#Yin").toggle()
                })
                $(document).on("click", "#XZ_S", function () {
                    $("#addwl_main").css({ "display": "block" })
                    $("#Biaos").text("1")
                })
                $(document).on("click", "#XZ_SZ", function () {
                    $("#addwl_main").css({ "display": "block" })
                    $("#Biaos").text("2")
                })
                $(document).on("click", ".quxiao", function () {
                    $("#addwl_main").css({ "display": "none" })
                    $(".amt_v").val("")
                })
                //点击切换基础信息，备注信息，图纸沟通
                $(function () {
                    $("#divjibeng").click(function (e) {
                        $("#div1").css({ "display": "block" });
                        $("#div2").css({ "display": "none" });
                        $("#div3").css({ "display": "none" }); $(this).css({ "background-color": "#fff" })
                        $(this).siblings().css({ "background-color": "#ededed" })
                    })
                    $("#divbeizhu").click(function (e) {
                        $("#div2").css({ "display": "block" });
                        $("#div1").css({ "display": "none" });
                        $("#div3").css({ "display": "none" }); $(this).css({ "background-color": "#fff" })
                        $(this).siblings().css({ "background-color": "#ededed" })
                    })
                    $("#divtuzhi").click(function (e) {
                        $("#div3").css({ "display": "block" });
                        $("#div1").css({ "display": "none" });
                        $("#div2").css({ "display": "none" }); $(this).css({ "background-color": "#fff" })
                        $(this).siblings().css({ "background-color": "#ededed" })
                    })
                })
            })//获取图纸信息
            function gettuz() {
                var kan = $("#shenDan").text();
                $.ajax({
                    url: "/Application/Application",
                    type: "POST",
                    data: { "App_ban": kan, "state": 3 },
                    success: function (sjik) {

                        $("#div3__tb tr").remove();
                        $.each(sjik, function (i, item) {
                            var x = item.De_dizhi
                            var $tr = $(`
                                                        <tr class="log_tr">
                                                            <td style="display:none">${item.DE_id}</td>
                                                            <td>${i + 1}</td>
                                                            <td><input type="text" value="${item.DE_TZname}"/></td>
                                                            <td>${item.De_shijian}</td>
                                                            <td>${item.De_ren}</td>
                                                            <td>/<a href="/Contracts/Download_file?path=${x}" id="log_SZ">下载</a></td>
                                                        </tr>
                                                        `);
                            $("#div3__tb").append($tr);
                        })
                    },
                    error: function () {
                        alert("erroer");
                    },
                })
            }
            //获取备注信息
            function gettbz() {
                var kan = $("#shenDan").text();
                $.ajax({
                    url: "/Application/Application",
                    type: "POST",
                    data: { "App_ban": kan, "state": 4 },
                    success: function (sjik) {
                        $("#div2_div div").remove();
                        $.each(sjik, function (i, item) {
                            var $tr = $(`
                                <div>
                                    <div>
                                        <span>${item.B_BR}</span><span>${item.B_Date}</span>
                                    </div>
                                    <div>
                                        ${item.B_bei}
                                    </div>
                                </div>`);
                            $("#div2_div").append($tr);
                        })
                    },
                    error: function () {
                        alert("erroer");
                    },
                })
            }
        </script>
    }
</div>